package com.yunhe.control;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.yunhe.bean.Board;
import com.yunhe.service.GoodsBoardService;
import com.yunhe.util.MySession;

/**
 * Servlet implementation class goodClassifyAdd
 */
/*@WebServlet(name = "goodClassifyAdd.do", urlPatterns = { "/goodClassifyAdd.do" })*/
@WebServlet("/goodClassifyAdd.do")
public class goodClassifyAdd extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public goodClassifyAdd() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String bName = request.getParameter("classifyName");
		System.out.println(bName);
		SqlSession se = new MySession().getSession();
		Board board = new Board();
		board.setBname(bName);
		boolean n = new GoodsBoardService().getBoardExist(bName);
		if(n==true) {
			se.insert("com.yun.dao.GoodsBoardDao.insertBoard",board);
			se.commit();
			request.getRequestDispatcher("/hou/goods-classify.jsp").forward(request,response);
		}else {
			System.out.println("该板块已存在");
			response.sendRedirect("/hou/goods-classify-add.jsp");
		}

	}

}
